<template>
  <el-container>
    <el-header height="60px">
      <el-col :span="12"><div class="grid-content bg-purple" align="left">
        <img src="../assets/logo.png" width="150px" height="50px">
      </div></el-col>
      <el-col :span="12"><div class="grid-content bg-purple-light" align="right">
        <el-button plain>登录</el-button>
        <el-button plain>注册</el-button>
      </div></el-col>
    </el-header>
    <el-main>

      <!--商品图片及名字、价格-->

      <el-row v-for="pro in pros">
        <el-col :span="8">
          <div class="grid-content bg-purple proimg" >

            <img class="proimg" :src="pro.img" />

        </div>
        </el-col>
        <el-col :span="16"><div class="grid-content bg-purple-light">

          <el-row>
            <el-col :span="12"><div align="right" class="grid-content bg-purple">
              <h3>商品名称</h3>
            </div></el-col>
            <el-col :span="12"><div class="grid-content bg-purple-light" >
              <h3>{{pro.name}}</h3>
            </div></el-col>
          </el-row>
          <el-row>
            <el-col :span="12"><div align="right" class="grid-content bg-purple">
              <h3>商品价格</h3>
            </div></el-col>
            <el-col :span="12"><div class="grid-content bg-purple-light" >
              <h3>{{pro.price}}</h3>
            </div></el-col>
          </el-row>
          <el-row>
            <el-col :span="12"><div align="right" class="grid-content bg-purple">
              <h3>商品数量</h3>
            </div></el-col>
            <el-col :span="12"><div class="grid-content bg-purple-light">
              <h3><el-input v-model="count"></el-input></h3>
            </div></el-col>
          </el-row>
          <el-row>
            <el-col :span="24"><div class="grid-content bg-purple">
              <el-button type="danger" @click="gtCart()">加入购物车</el-button>
            </div></el-col>

          </el-row>

        </div></el-col>

      </el-row>


      <!--商品详情-->

      <el-row>
        <el-col :span="24"><div class="grid-content bg-purple">



        </div></el-col>
      </el-row>



    </el-main>
  </el-container>
</template>

<script>
export default {
    name: "ProductInfo",
  data(){
      return{
        pid:this.$route.params.pid,
        pros: [
          {
          "id": 10086,
          "name": "HUAWEI P30",
          "desc": "华为P系列",
          "price": 10086,
          "img": "/static/p1.jpg"
            }
          ],
        count:1

    }

  },
  created(){
      this.getProduct();

  },
  methods:{
      getProduct(){
        const vm = this;
        vm.axios({
          method: 'GET',
          //url: 'http://localhost/product/getProductById?pid='+vm.pid
          url: "http://mock.amzpiper.com/mock/60b5e3338b2bd30020765379/example/info"
        }).then(function(resp){
          vm.pros = resp.data;
          console.log(resp.data)
        })
      },
    gtCart:function(){
        const p =  {
          userId:20090704001,
          pid:this.pro.id,
          count:this.count

        };

        this.$router.push({ name: 'Cart', params:p});
    }
  }
}
</script>

<style scoped>

  .proimg{
    width: 400px;
    height: 500px;
  }

  .el-header, .el-footer {
    margin-top: 10px;
    background-color: #ffffff;
    color: #333;
    text-align: center;

  }



  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 160px;
  }

  body > .el-container {
    margin-bottom: 40px;
  }




</style>
